package com.jia.config;

import com.jia.interceptor.InterceptorHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }


    @Autowired
    private InterceptorHandler interceptorHandler;

    @Autowired
    private NoAuthUrls authUrls;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(interceptorHandler)
                //放过哪些请求
//                .excludePathPatterns("/admin/system/index/login","/admin/system/index/getValidateCode")
                .excludePathPatterns(authUrls.getNoauthurls())
                //其他都要验证
                .addPathPatterns("/**");
    }

}
